/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package interfaces;

import dao.CidadeDAO;
import dao.LocaisVisitadosDAO;
import java.util.ArrayList;
import java.util.List;
import javax.swing.JOptionPane;
import modelo.Cidade;

/**
 *
 * @author marcelosiedler
 */
public class FrameCidadeGerencia extends javax.swing.JInternalFrame {

    List<Cidade> lista = new ArrayList<Cidade>();
    Integer contCodigo = 0;
    Integer posicaolista;

    public FrameCidadeGerencia() {
        initComponents();
        lista = cid.Listar();
        /* Set the Nimbus look and feel */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel.
         * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html 
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(FrameCidadeGerencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(FrameCidadeGerencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(FrameCidadeGerencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(FrameCidadeGerencia.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /* Create and display the form */
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        jInternalFrame1 = new javax.swing.JInternalFrame();
        jPanel2 = new javax.swing.JPanel();
        jLDic1 = new javax.swing.JLabel();
        jLDic2 = new javax.swing.JLabel();
        jLDic3 = new javax.swing.JLabel();
        txtDica1 = new javax.swing.JTextField();
        txtDica2 = new javax.swing.JTextField();
        txtDica3 = new javax.swing.JTextField();
        jPanel3 = new javax.swing.JPanel();
        jLItem1 = new javax.swing.JLabel();
        jLItem2 = new javax.swing.JLabel();
        txtItem1 = new javax.swing.JTextField();
        txtItem2 = new javax.swing.JTextField();
        jPanel4 = new javax.swing.JPanel();
        ButInserir = new javax.swing.JButton();
        ButAtualizar = new javax.swing.JButton();
        ButNovo = new javax.swing.JButton();
        ButRemover = new javax.swing.JButton();
        jPanel1 = new javax.swing.JPanel();
        jLCod1 = new javax.swing.JLabel();
        txtCod = new javax.swing.JTextField();
        jLNome1 = new javax.swing.JLabel();
        txtNomeCid = new javax.swing.JTextField();
        jLDesc1 = new javax.swing.JLabel();
        jScrollPane7 = new javax.swing.JScrollPane();
        txtDesc = new javax.swing.JTextArea();
        jPanel5 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jPanel7 = new javax.swing.JPanel();
        ButPrimeiro2 = new javax.swing.JButton();
        ButAnterior2 = new javax.swing.JButton();
        ButProximo2 = new javax.swing.JButton();
        ButUltimo2 = new javax.swing.JButton();

        setClosable(true);
        setIconifiable(true);
        setMaximizable(true);
        setTitle("Gerenciar cidade");

        jInternalFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 0, Short.MAX_VALUE)
        );

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dicas", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), java.awt.Color.darkGray)); // NOI18N

        jLDic1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLDic1.setText("Dica 01:");

        jLDic2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLDic2.setText("Dica 02:");

        jLDic3.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLDic3.setText("Dica 03:");

        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Itens", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), java.awt.Color.darkGray)); // NOI18N

        jLItem1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLItem1.setText("Item 01:");

        jLItem2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLItem2.setText("Item 02:");

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addGap(23, 23, 23)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLItem1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtItem1, javax.swing.GroupLayout.PREFERRED_SIZE, 228, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel3Layout.createSequentialGroup()
                        .addComponent(jLItem2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtItem2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLItem1)
                    .addComponent(txtItem1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(18, 18, 18)
                .addGroup(jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLItem2)
                    .addComponent(txtItem2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLDic3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(txtDica3))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLDic2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDica2))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLDic1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                        .addComponent(txtDica1, javax.swing.GroupLayout.PREFERRED_SIZE, 487, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 34, Short.MAX_VALUE)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(jLDic1)
                            .addComponent(txtDica1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtDica2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLDic2, javax.swing.GroupLayout.Alignment.TRAILING))
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                            .addComponent(txtDica3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jLDic3))
                        .addGap(163, 163, 163))))
        );

        jPanel4.setBorder(javax.swing.BorderFactory.createTitledBorder("Opções"));

        ButInserir.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButInserir.setText("Inserir");
        ButInserir.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButInserirActionPerformed(evt);
            }
        });

        ButAtualizar.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButAtualizar.setText("Atualizar");
        ButAtualizar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButAtualizarActionPerformed(evt);
            }
        });

        ButNovo.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButNovo.setText("Novo");
        ButNovo.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButNovoActionPerformed(evt);
            }
        });

        ButRemover.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButRemover.setText("Excluir");
        ButRemover.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButRemoverActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(ButAtualizar, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButNovo, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel4Layout.createSequentialGroup()
                        .addComponent(ButInserir, javax.swing.GroupLayout.PREFERRED_SIZE, 81, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(ButRemover, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButRemover)
                    .addComponent(ButInserir))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButAtualizar)
                    .addComponent(ButNovo))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Dados", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Tahoma", 0, 14), java.awt.Color.darkGray)); // NOI18N

        jLCod1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLCod1.setText("Código:");

        txtCod.setEditable(false);

        jLNome1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLNome1.setText("Nome :");

        jLDesc1.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        jLDesc1.setText("Descrição:");

        txtDesc.setColumns(20);
        txtDesc.setRows(5);
        jScrollPane7.setViewportView(txtDesc);

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jLDesc1)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, 284, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jLNome1)
                            .addComponent(jLCod1))
                        .addGap(25, 25, 25)
                        .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(txtCod, javax.swing.GroupLayout.PREFERRED_SIZE, 64, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(txtNomeCid, javax.swing.GroupLayout.PREFERRED_SIZE, 285, javax.swing.GroupLayout.PREFERRED_SIZE))))
                .addContainerGap(11, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jLCod1)
                    .addComponent(txtCod, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addGap(16, 16, 16)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(txtNomeCid, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLNome1))
                .addGap(18, 18, 18)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jLDesc1)
                    .addComponent(jScrollPane7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        jPanel5.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));

        jLabel1.setText("Carregar imagem ");

        javax.swing.GroupLayout jPanel5Layout = new javax.swing.GroupLayout(jPanel5);
        jPanel5.setLayout(jPanel5Layout);
        jPanel5Layout.setHorizontalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(100, 100, 100)
                .addComponent(jLabel1)
                .addContainerGap(114, Short.MAX_VALUE))
        );
        jPanel5Layout.setVerticalGroup(
            jPanel5Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel5Layout.createSequentialGroup()
                .addGap(69, 69, 69)
                .addComponent(jLabel1)
                .addContainerGap(82, Short.MAX_VALUE))
        );

        jPanel7.setBorder(javax.swing.BorderFactory.createTitledBorder("Navegação"));

        ButPrimeiro2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButPrimeiro2.setText("Primeiro");
        ButPrimeiro2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButPrimeiro2ActionPerformed(evt);
            }
        });

        ButAnterior2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButAnterior2.setText("Anterior");
        ButAnterior2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButAnterior2ActionPerformed(evt);
            }
        });

        ButProximo2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButProximo2.setText("Proximo");
        ButProximo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButProximo2ActionPerformed(evt);
            }
        });

        ButUltimo2.setFont(new java.awt.Font("Tahoma", 0, 14)); // NOI18N
        ButUltimo2.setText("Ultimo");
        ButUltimo2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                ButUltimo2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel7Layout = new javax.swing.GroupLayout(jPanel7);
        jPanel7.setLayout(jPanel7Layout);
        jPanel7Layout.setHorizontalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(8, 8, 8)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(ButPrimeiro2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ButUltimo2, javax.swing.GroupLayout.PREFERRED_SIZE, 83, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel7Layout.createSequentialGroup()
                        .addComponent(ButProximo2)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(ButAnterior2)))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
        jPanel7Layout.setVerticalGroup(
            jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel7Layout.createSequentialGroup()
                .addGap(19, 19, 19)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButPrimeiro2)
                    .addComponent(ButUltimo2))
                .addGap(18, 18, 18)
                .addGroup(jPanel7Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(ButProximo2)
                    .addComponent(ButAnterior2))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(18, 18, 18)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                    .addGroup(layout.createSequentialGroup()
                        .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addGap(0, 15, Short.MAX_VALUE)))
                .addContainerGap())
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 487, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 486, Short.MAX_VALUE)))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(layout.createSequentialGroup()
                        .addGap(32, 32, 32)
                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                            .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                            .addGroup(layout.createSequentialGroup()
                                .addGap(13, 13, 13)
                                .addComponent(jPanel7, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                                .addGap(18, 18, 18)
                                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))))
                    .addGroup(layout.createSequentialGroup()
                        .addGap(62, 62, 62)
                        .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 19, Short.MAX_VALUE)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 142, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(27, Short.MAX_VALUE))
            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(0, 231, Short.MAX_VALUE)
                    .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 231, Short.MAX_VALUE)))
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void ButInserirActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButInserirActionPerformed
        if (txtNomeCid.getText().equals("") || txtDesc.getText().equals("")
                || txtDica1.getText().equals("") || txtDica1.getText().equals("")
                || txtDica3.getText().equals("") || txtItem1.getText().equals("")
                || txtItem2.getText().equals("")) {
            JOptionPane.showMessageDialog(null, "Todos os campos são obrigatórios");

        } else {

            cid.Cadastrar(CarregaDados());

            JOptionPane.showMessageDialog(null, "Cidade inserida com sucesso");
            LimparDados();
            cid.Listar();
        }
    }//GEN-LAST:event_ButInserirActionPerformed

    private void ButAtualizarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButAtualizarActionPerformed
//        if (txtNomeCid.getText().equals("") || txtDesc.getText().equals("")
//                || txtDica1.getText().equals("") || txtDica1.getText().equals("")
//                || txtDica3.getText().equals("") || txtItem1.getText().equals("")
//                || txtItem2.getText().equals("")) {
//            JOptionPane.showMessageDialog(null, "Todos os campos são obrigatórios");
//        } else {
//
//            Integer codigo = Integer.parseInt(txtCod.getText());
//            for (Cidade c : lista) {
//                if (codigo == c.getCodigo()) {
//                    c.setNomeCid(txtNomeCid.getText());
//                    c.setDescricao(txtDesc.getText());
//                    c.setDica1(txtDica1.getText());
//                    c.setDica2(txtDica1.getText());
//                    c.setDica3(txtDica3.getText());
//                    c.setItemValor1(txtItem1.getText());
//                    c.setItemValor2(txtItem2.getText());
//                    break;
//                }
//
//            }
//            JOptionPane.showMessageDialog(null, "Cidade atualizada com sucesso");
//            LimparDados();
//        }
    }//GEN-LAST:event_ButAtualizarActionPerformed

    private void ButNovoActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButNovoActionPerformed
        LimparDados();
    }//GEN-LAST:event_ButNovoActionPerformed

    private void ButPrimeiro2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButPrimeiro2ActionPerformed

        Cidade c = lista.get(0);

        txtCod.setText(c.getCodigo().toString());
        txtNomeCid.setText(c.getNomeCid());
        txtDesc.setText(c.getDescricao());
        txtDica1.setText(c.getDica1());
        txtDica2.setText(c.getDica2());
        txtDica3.setText(c.getDica3());
        txtItem1.setText(c.getItemValor1());
        txtItem2.setText(c.getItemValor2());

        posicaolista = 0;
    }//GEN-LAST:event_ButPrimeiro2ActionPerformed

    private void ButAnterior2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButAnterior2ActionPerformed
        if (posicaolista > 0) {
            posicaolista = posicaolista - 1;
            Cidade c = lista.get(posicaolista);

            txtCod.setText(c.getCodigo().toString());
            txtNomeCid.setText(c.getNomeCid());
            txtDesc.setText(c.getDescricao());
            txtDica1.setText(c.getDica1());
            txtDica2.setText(c.getDica2());
            txtDica3.setText(c.getDica3());
            txtItem1.setText(c.getItemValor1());
            txtItem2.setText(c.getItemValor2());

            posicaolista = lista.size() - 1;
        }
    }//GEN-LAST:event_ButAnterior2ActionPerformed

    private void ButProximo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButProximo2ActionPerformed

        if (posicaolista < (lista.size() - 1)) {
            posicaolista = posicaolista + 1;
            Cidade c = lista.get(posicaolista);
            txtCod.setText(c.getCodigo().toString());
            txtNomeCid.setText(c.getNomeCid());
            txtDesc.setText(c.getDescricao());
            txtDica1.setText(c.getDica1());
            txtDica2.setText(c.getDica2());
            txtDica3.setText(c.getDica3());
            txtItem1.setText(c.getItemValor1());
            txtItem2.setText(c.getItemValor2());

            posicaolista = lista.size() - 1;
        }
    }//GEN-LAST:event_ButProximo2ActionPerformed

    private void ButUltimo2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButUltimo2ActionPerformed
        Cidade c = lista.get((lista.size() - 1));
        txtCod.setText(c.getCodigo().toString());
        txtNomeCid.setText(c.getNomeCid());
        txtDesc.setText(c.getDescricao());
        txtDica1.setText(c.getDica1());
        txtDica2.setText(c.getDica2());
        txtDica3.setText(c.getDica3());
        txtItem1.setText(c.getItemValor1());
        txtItem2.setText(c.getItemValor2());

        posicaolista = lista.size() - 1;
    }//GEN-LAST:event_ButUltimo2ActionPerformed

    private void ButRemoverActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ButRemoverActionPerformed
        Integer confirma = JOptionPane.showConfirmDialog(null, "Dejesa excluir");
        if (confirma == 0) {
            c.setCodigo(Integer.parseInt(txtCod.getText()));
            cid.Excluir(c);
            LimparDados();
            lista = cid.Listar();

        }
    }//GEN-LAST:event_ButRemoverActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton ButAnterior2;
    private javax.swing.JButton ButAtualizar;
    private javax.swing.JButton ButInserir;
    private javax.swing.JButton ButNovo;
    private javax.swing.JButton ButPrimeiro2;
    private javax.swing.JButton ButProximo2;
    private javax.swing.JButton ButRemover;
    private javax.swing.JButton ButUltimo2;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLCod1;
    private javax.swing.JLabel jLDesc1;
    private javax.swing.JLabel jLDic1;
    private javax.swing.JLabel jLDic2;
    private javax.swing.JLabel jLDic3;
    private javax.swing.JLabel jLItem1;
    private javax.swing.JLabel jLItem2;
    private javax.swing.JLabel jLNome1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel7;
    private javax.swing.JScrollPane jScrollPane7;
    private javax.swing.JTextField txtCod;
    private javax.swing.JTextArea txtDesc;
    private javax.swing.JTextField txtDica1;
    private javax.swing.JTextField txtDica2;
    private javax.swing.JTextField txtDica3;
    private javax.swing.JTextField txtItem1;
    private javax.swing.JTextField txtItem2;
    private javax.swing.JTextField txtNomeCid;
    // End of variables declaration//GEN-END:variables
CidadeDAO cid = new CidadeDAO();
    Cidade c = new Cidade();

    public Cidade CarregaDados() {

        c.setNomeCid(txtNomeCid.getText());
        c.setDescricao(txtDesc.getText());
        c.setDica1(txtDica1.getText());
        c.setDica2(txtDica2.getText());
        c.setDica3(txtDica3.getText());
        c.setItemValor1(txtItem1.getText());
        c.setItemValor2(txtItem2.getText());
        return c;
    }

    public void LimparDados() {

        txtNomeCid.setText(null);
        txtDesc.setText(null);
        txtDica1.setText(null);
        txtDica2.setText(null);
        txtDica3.setText(null);
        txtItem1.setText(null);
        txtItem2.setText(null);

    }
}
